package com.gjm.demo;

import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController {

    @RequestMapping("/m1")
    public String method1(String keyword) {
        return keyword;
    }

    @RequestMapping("/m2")
    public String method2(String userName, String password) {
        return "userName: " + userName + ", password: " + password;
    }

    @RequestMapping("/m3")
    public String method3(Integer num) {//Integer可以为null，若客户端不传参数，num就是null
        return "接收参数: " + num;
    }

    @RequestMapping("/m4")
    public String method4(int num) {//int不能为null，客户端必须传参
        return "接收参数: " + num;
    }

    @RequestMapping(value = "/m5", method = RequestMethod.GET)
    public String method5(String keyword) {
        return "接收参数: " + keyword;
    }

    @RequestMapping(value = "/m6", method = RequestMethod.POST)
    public String method6(String keyword) {
        return "接收参数: " + keyword;
    }

    @GetMapping("/m8")
    public String method8(String keyword) {
        return "接收参数: " + keyword;
    }

    @PostMapping("/m9")
    public String method9(String keyword) {
        return "接收参数: " + keyword;
    }

    @RequestMapping("/m10")
    public String method10(UserInfo userInfo) {
        return "UserInfo: " + userInfo.toString();
    }

    @RequestMapping("/m11")
    public String method11(@RequestParam(value = "q", required = false) String keyword) {
        //使用RequestParam，就使得将q的值赋给keyword，但只能使用q传参
        //RequestParam表示必传参数，若不传q就会报错；传入false，就表示不是必传参数，不传q，keyword就是null
        return "接收参数: " + keyword;
    }

    @RequestMapping("/m12")
    public String method12(@RequestParam List<Integer> list) {//将list转换为数组
        return list.toString();
    }

    @RequestMapping("/m13")
    public String method13(String[] arr) {
        return Arrays.toString(arr);
    }
}
